package com.googlecode.jawb.clues.types;

import java.io.InputStream;

/**
 * Interface for custom converter with direct access to the input stream. It is
 * preferred not to use this converter when possible and use
 * {@link StaticLengthType} converter instead. The reason is that this converter
 * may directly access the input stream and therefore cause problems if
 * programmed inappropriately.
 * 
 * @see #fromByteArray(InputStream)
 * @see #toByteArray(Object)
 */
public interface DynamicLengthType {
	/**
	 * Loads any amount of bytes from the input stream and constructs object. It
	 * is programmer's responsibility to ensure that converter will be correctly
	 * used and returned Object might be casted to the type of field where it is
	 * used.
	 * 
	 * @param inputStream
	 *            Stream from which bytes might be loaded.-
	 * @return Object constructed from loaded bytes.
	 */
	public Object fromByteArray(InputStream inputStream);
	
	/**
	 * Converts given object to array of bytes. It is programmer's
	 * responsibility to ensure that converter will be correctly used and passed
	 * Object is of correct type (with which this converter may work).
	 * 
	 * @param object
	 *            Object to be converted.
	 * @return Array of bytes to be saved into output stream.
	 */
	public byte[] toByteArray(Object object);
}
